package edu.ahut.designpattern.chainresponsibility.demo;

import java.math.BigInteger;

public class BigIntegerFactorialHandler implements Handler {
    @Override
    public void handleRequest(int n) {
        if (n < 3000) {
            BigInteger s = new BigInteger("1");
            for (int i = 2; i <= n; i++) {
                s = s.multiply(new BigInteger(Integer.toString(i)));

            }
            System.out.println(s);

        } else if (next != null) {
            next.handleRequest(n);
        }
    }

    @Override
    public void setNextHandler(Handler next) {
        this.next = next;

    }

    Handler next;
}
